﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MillerApp.CommonLib.LogProvider
{
    public class FileLogProvider : ILogProvider
    {
        private string logFilePath = string.Empty;

        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="logMsg"></param>
        public  void WriteLog(string logMsg)
        {
            lock (this)
            {
                using (StreamWriter sw = new StreamWriter(logFilePath, true))
                {
                    sw.WriteLine(logMsg);
                    sw.Flush();
                    sw.Close();
                }
            }
        }

        public FileLogProvider(string logFilePath)
        {
            this.logFilePath = logFilePath;
            lock (this)
            {
                if (System.IO.File.Exists(logFilePath)==false)
                {
                    System.IO.FileStream fs = new FileStream(logFilePath, System.IO.FileMode.CreateNew);
                    fs.Flush();
                    fs.Close();
                }
            }
        }
    }
}
